package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "订单相关接口")
public class OrderController {
    @Resource
    private OrderService orderService;

    /*
    * 订单搜索
    * */
    @GetMapping("/conditionSearch")
    public Result<PageResult> search(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单搜索：{}",ordersPageQueryDTO);
        PageResult page = orderService.pageQuery(ordersPageQueryDTO);
        return Result.success(page);
    }

    /*
    * 根据订单id来查询订单明细
    * */
    @GetMapping("/details/{id}")
    public Result<OrderVO> getDetailByOrderId(@PathVariable Long id){
        log.info("根据订单id查询订单明细,{}",id);
        OrderVO orderVO = orderService.queryDetailsById(id);
        return Result.success(orderVO);
    }

    /*
     * 接单
     * */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("商家接单:{}",ordersConfirmDTO);
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /*
     * 派送
     * */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        log.info("商家派送,{}",id);
        orderService.delivery(id);
        return Result.success();
    }

    /*
     * 拒单
     * */
    @PutMapping("/rejection")
    public Result reject(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("商家拒单,{}",ordersRejectionDTO);
        orderService.reject(ordersRejectionDTO);
        return Result.success();
    }

    /*
    * 完成订单
    * */
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        log.info("完成订单id:{}",id);
        orderService.complete(id);
        return Result.success();
    }

    /*
    * 删除订单
    * */
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("删除订单:{}",ordersCancelDTO);
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /*
    * 订单数据总览
    * */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> orderStatistics(){
        log.info("订单信息总览");
        OrderStatisticsVO statistics = orderService.getStatistics();
        return Result.success(statistics);
    }

}
